/**
 * 
 */
package com.evon.yardmanagement.service;

import java.util.List;

import com.evon.yardmanagement.model.Section;
import com.evon.yardmanagement.dao.SectionDAO;

import com.evon.yardmanagement.model.Vendor;
import com.evon.yardmanagement.model.Section;
import com.evon.yardmanagement.model.Yard;
import com.evon.yardmanagement.transformer.SectionTransformer;
import com.evon.yardmanagement.ui.dto.SectionDTO;

/**
 * @author Sandeep
 *
 */
public class SectionManagementService implements ISectionManagementSevice{

	SectionDAO sectionDAO = new SectionDAO();

	public boolean deactivateSection(Section section) {
		// TODO Auto-generated method stub
		return false;
	}

	public List<Section> getAllSections() {
		// TODO Auto-generated method stub
		return sectionDAO.findAll();
	}

	public List<Section> getSectionDetails(Vendor company) {
		// TODO Auto-generated method stub
		return null;
	}
	public int addSection(SectionDTO sectionDTO) {
		Section section = SectionTransformer.transformToModel(sectionDTO);
		sectionDAO.saveOrUpdate(section);
		return section.getId();
	}


	public List<Section> getAllSectionsForExportToExcel() {
		// TODO Auto-generated method stub
		return sectionDAO.findAll();
	}

	
	public List<Section> getSectionByYardId(Integer id) {
		// TODO Auto-generated method stub
		Yard yard = new Yard();
		yard.setId(id);
		return sectionDAO.findByProperty("yard", yard);
	}

	
	public List<Section> getSectionBySectionId(Integer integer) {
		// TODO Auto-generated method stub
		return sectionDAO.findByProperty("id", integer);
	}

	public boolean setActiveSectionBySectionId(List<Section> sectionList) {
		// TODO Auto-generated method stub
	
		for (Section section : sectionList) {
			sectionDAO.saveOrUpdate(section);
		}
		return true;
	}	
	
	public boolean setActiveSectionByYardId(int yardId) {
		// TODO Auto-generated method stub
	
		
			sectionDAO.setActive(yardId);
		
		return true;
	}
	
	public boolean setDeActiveSectionByYardId(int yardId) {
		// TODO Auto-generated method stub
	
		
			sectionDAO.setDeActive(yardId);
		
		return true;
	}

/**
	 * Save the list of sections in DB.
	 * @param data
	 */
	public void importSections(List<Section> data) {
		 if(data != null && !data.isEmpty()){
			 for(Section section : data){
				 sectionDAO.saveOrUpdate(section);
			 }
		 }
		
	}	
}
